home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / amusemen / vgatarot.000 / vgatarot / VGATarot-0.3 / vgaceltic.c < prev    next >
C/C++ Source or Header  |  1994-05-24  |  8KB  |  276 lines

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<strings.h>
  4. #include<allinc.h>
  5. #include<unistd.h>
  6. #include<signal.h>
  7. #include<vga.h>
  8. #include<vgagl.h>
  9. #include<vgakeyboard.h>
  10. #include<sys/time.h>
  11. #include<sys/types.h>
  12. #include<fcntl.h>
  13. #include"zsoftpcx.h"
  14.  
  15. typedef struct timeval t_tv;
  16. typedef struct timezone t_tz;
  17.     
  18. unsigned long giverand(unsigned long range,int seedadd);
  19.  
  20. void viewpcx(int XBeg,int YBeg,char *libname,char *indexname,int cnum,int orientation);
  21.  
  22. void north_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel);
  23.  
  24. void east_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel);
  25.  
  26. void south_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel);
  27.  
  28. void west_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel);        
  29.  
  30.  
  31.  
  32. void main(int argc,char *argv[]) {
  33.     char question[5000];
  34.     char name[200];
  35.     char nuls[80];
  36.     int hand[11][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  37.                {0,0},{0,0},{0,0},{0,0},{0,0}};
  38.     int done=0;
  39.     int deckx[78] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  40.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  41.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };    
  42.     int vgamode=G800x600x256;
  43.     char posit[11][80] = {"Significator","Cover","Cross","Crown","Beneath","Behind",
  44.                   "Before","Yourself","Your House","Your hopes and fears",
  45.                   "Outcome"};
  46.     /* significator is at 0,0
  47.        cover is at 325,200
  48.        cross is at 239,295
  49.        before is at 475,200
  50.        behind is at 175,200
  51.        crown is at 325,0
  52.        beneath is at 325,400
  53.        himself is at 700,425
  54.        house is at 600,275
  55.        hopes is at 700,125
  56.        outcome is at 600,0
  57.        
  58.     */
  59.     int pos[11][2]={{0,0},{325,200},{239,295},{475,200},{175,200},{325,0},{325,400},
  60.             {700,425},{600,275},{700,125},{600,0}};
  61.     int seed,x,y;
  62.  
  63.     printf("\nVGATarot - Celtic Cross V0.3\n");
  64.     printf("\nPlease enter your name (first and last) > ");
  65.     gets(name);
  66.     printf("Please enter your question\n> ");
  67.     gets(question);
  68.     
  69.     for(x=0,seed=0;x!=strlen(name);x++,seed+=name[x]);
  70.     for(x=0;x!=strlen(question);x++,seed+=question[x]);
  71.  
  72.     printf("Please choose a significator\n");
  73.     for(x=0;x!=78;x+=3) printf("[%02d] %-25s [%02d] %-25s [%02d] %-25s\n",x+1,deck[x],x+2,deck[x+1],x+3,deck[x+2]);
  74.  
  75.     while(!done) {
  76.         printf("\n> ");
  77.         gets(nuls);
  78.     
  79.         if((atoi(nuls)<1)||(atoi(nuls)>78)) {
  80.             printf("please choose a correct significator (1-78)\n"); } else done = 1; }
  81.         
  82.     deckx[atoi(nuls)-1]=1;
  83.     hand[0][0]=atoi(nuls)-1;
  84.     hand[0][1]=0;
  85.     y=1;
  86.     done=0;
  87.     
  88.     while(!done) {
  89.         x=(int)giverand(78,seed);
  90.         if(deckx[x]==0) {
  91.             deckx[x]=1;
  92.             hand[y][0]=x; 
  93.             if((int)giverand(100,seed)>50) hand[y][1]=1; else hand[y][1]=0;
  94.             y++; } 
  95.         if(y==11) done=1; }
  96.  
  97.     if(!vga_hasmode(vgamode)) {
  98.         printf("mode is unsupported\n"); 
  99.         exit(-1); }
  100.         
  101.     vga_setmode(vgamode);
  102.     gl_setcontextvga(vgamode);
  103.     gl_enableclipping();
  104.     gl_setwritemode(WRITEMODE_OVERWRITE);
  105.     
  106.     printf("\n");
  107.  
  108.     for(x=0;x!=11;x++) {
  109.         if(hand[x][1]==0) seed=1; else seed=3;
  110.         if(x==2) { if(hand[x][1]==0) seed=2; else seed=4; }
  111.         printf("%-20s : %s %s\n",posit[x],deck[hand[x][0]],hand[x][1]==0?"":"Reversed");
  112.         viewpcx(pos[x][0],pos[x][1],"tarotlib.lbr","tarotlib.index",hand[x][0],seed); } 
  113.         
  114.     printf("\n");
  115.  
  116.     getchar();
  117.     vga_setmode(TEXT);
  118.     
  119.     exit(1); }
  120.     
  121. unsigned long giverand(unsigned long range,int seedadd)
  122.     { 
  123.     t_tv tv;
  124.     t_tz tz;
  125.         
  126.     gettimeofday(&tv,&tz);
  127.     srandom((unsigned int)tv.tv_usec+(unsigned int)seedadd);
  128.     return (unsigned long)((random()%range)+1); }
  129.  
  130. void viewpcx(int XBeg,int YBeg,char *libname,char *indexname,int cnum,int orientation) { 
  131.     int fi; /* index file */
  132.     int fp; /* data file */
  133.     unsigned char *data_pix;
  134.     unsigned long foffset;
  135.     unsigned long flength;
  136.     int XPos,YPos,XMax,YMax;
  137.     zhead pcx;
  138.     Palette pal;
  139.     unsigned long x;
  140.     unsigned int y,z,inbyte;
  141.     unsigned char inc;
  142.  
  143.     if((fi=open(indexname,O_RDONLY))==-1) {
  144.         vga_setmode(TEXT);
  145.         printf("cannot open index file\n");
  146.         exit(-1); }
  147.         
  148.     lseek(fi,cnum*8,SEEK_SET); /* get the correct index */
  149.     
  150.     read(fi,&foffset,sizeof(foffset)); /* get the offset */
  151.     read(fi,&flength,sizeof(flength)); /* get the length */
  152.     
  153.     close(fi); /* close index file */
  154.     
  155.     if((fp=open(libname,O_RDONLY))==-1) { /* open library file */
  156.         vga_setmode(TEXT);
  157.         printf("cannot open library file\n");
  158.         exit(-1); }
  159.     
  160.     lseek(fp,foffset,SEEK_SET); /* go to correct offset in library */
  161.             
  162.     if(read(fp,&pcx,sizeof(pcx))!=sizeof(pcx)) { /* read PCX header information */
  163.         vga_setmode(TEXT);
  164.         printf("cannot read header information of picture %d\n",cnum);
  165.         exit(-1); }
  166.         
  167.     XMax=(int)pcx.x2; YMax=(int)pcx.y2; /* set the x and y dimensions of the picture */
  168.     
  169.     lseek(fp,128-sizeof(pcx),SEEK_CUR);
  170.     
  171.     if((data_pix=(char *)malloc(flength-128))==NULL) { /* get picture memory */
  172.         vga_setmode(TEXT);
  173.         printf("couldn't allocate picture data memory\n");
  174.         exit(-1); }    
  175.         
  176.     if(((unsigned long)read(fp,data_pix,(flength-128)))!=(flength-128)) { /* read picture data */
  177.         vga_setmode(TEXT);
  178.         printf("couldn't read in picture data\n");
  179.         exit(-1); }
  180.         
  181.     close(fp); /* close library file */
  182.     
  183.     data_pix+=(flength-128-768); /* get to the palette data */
  184.                 
  185.     for(x=0;x<255;x++) { /* set the palette data */
  186.         inc=*data_pix++;
  187.         pal.color[x].red=(inc/4);
  188.         inc=*data_pix++;
  189.         pal.color[x].green=(inc/4);
  190.         inc=*data_pix++;
  191.         pal.color[x].blue=(inc/4); }
  192.         
  193.     data_pix-=(flength-131); /* why 131?  I've no damn clue, but it works better than 128 */
  194.         
  195.     gl_setpalette(&pal); /* set the palette */
  196.     
  197.     switch(orientation) { /* set up correct orientation parameters */
  198.         case 1 : /* north */ 
  199.                     XMax=(int)pcx.x2+1;
  200.                     YMax=(int)pcx.y2;
  201.                     XPos=XBeg; 
  202.                     YPos=YBeg; 
  203.                     break;
  204.         case 2 : /* east */ 
  205.                     XMax=(int)pcx.x2+1;
  206.                     YMax=(int)pcx.y2;
  207.                     XPos=YBeg+YMax;
  208.                     YPos=XBeg;
  209.                     break;
  210.         case 3 : /* south */ 
  211.                     XMax=(int)pcx.x2+1;
  212.                     YMax=(int)pcx.y2;
  213.                     XPos=XBeg+XMax; 
  214.                     YPos=YBeg+YMax; 
  215.                     break;
  216.         case 4 : /* west */ 
  217.                     XMax=(int)pcx.x2+1;
  218.                     YMax=(int)pcx.y2;
  219.                     XPos=YBeg;
  220.                     YPos=XBeg+XMax;
  221.                     break; }
  222.     
  223.     for(x=0;x<(XMax*YMax);) { /* decode the picture */
  224.         inbyte=(unsigned int)*data_pix++;
  225.         if(inbyte>0xc0) { /* RLE compression */
  226.             inbyte-=0xc0;
  227.             y=(unsigned int)*data_pix++;
  228.             for(z=0;z<inbyte;z++) {
  229.                 x++;
  230.                 switch(orientation) {
  231.                     case 1 : north_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,y); break;
  232.                     case 2 : east_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,y); break;                    
  233.                     case 3 : south_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,y); break;
  234.                     case 4 : west_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,y); break; } } }
  235.         else {
  236.             x++;
  237.             switch(orientation) {
  238.                 case 1 : north_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,inbyte); break;
  239.                 case 2 : east_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,inbyte); break;                                    
  240.                 case 3 : south_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,inbyte); break;
  241.                 case 4 : west_pixel(&XPos,&YPos,XMax,YMax,XBeg,YBeg,inbyte); break; } } }
  242.                 
  243.         free(data_pix); } /* free the data, we are done */
  244.         
  245. void north_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel) {
  246.     if(*y>(ym+yb)) return;
  247.     gl_setpixel(*x,*y,pixel);
  248.     *x=*x+1;
  249.     if(*x==(xm+xb)) {
  250.         *x=xb;
  251.         *y=*y+1; } }
  252.         
  253. void south_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel) { 
  254.     if(*y==yb) return;
  255.     gl_setpixel(*x,*y,pixel);
  256.     *x=*x-1;
  257.     if(*x==xb) {
  258.         *x=xm+xb;
  259.         *y=*y-1; } }        
  260.         
  261. void west_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel) {
  262.     if(*x>(ym+yb)) return;
  263.     gl_setpixel(*x,*y,pixel);
  264.     *y=*y-1;
  265.     if(*y==xb) {
  266.         *y=xb+xm;
  267.         *x=*x+1; } }
  268.         
  269. void east_pixel(int *x,int *y,int xm,int ym,int xb,int yb,int pixel) {
  270.     if((*x)<yb) return;
  271.     gl_setpixel(*x,*y,pixel);
  272.     *y=*y+1;
  273.     if(*y==(xm+xb)) {
  274.         *y=xb;
  275.         *x=*x-1; } }
  276.